#include "thememanager.h"

#include <QtCore/QFile>
#include <QtCore/QTextStream>
#include <QtGui/QApplication>

using namespace core;

ThemeManager* themeManager = 0;

ThemeManager* ThemeManager::getInstance()
{
    if (themeManager == 0)
    {
        themeManager = new ThemeManager();
    }

    return themeManager;
}

void ThemeManager::destroy()
{
    delete themeManager;
    themeManager = 0;
}

void ThemeManager::applyTheme(const QString& resource, QApplication* app)
{
    QFile data(resource);

    if(data.open(QFile::ReadOnly)) {
        QTextStream styleIn(&data);

        const QString style = styleIn.readAll();
        data.close();

        app->setStyleSheet(style);

        m_themed = true;
    }
}

bool ThemeManager::themeApplied() const
{
    return m_themed;
}

ThemeManager::ThemeManager() : m_themed(false)
{

}

ThemeManager::~ThemeManager()
{

}
